<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8" />
  <title>a</title>
  <!-- 引入Vue -->
  <script type="text/javascript" src="../../js/vue.js"></script>
</head>

<body>
  <!-- 准备好一个容器-->
  <div id="demo">
    <h2>今天的天气{{text}}</h2>
    <img width="100" :src="url"><br>
    <button @click="chanClick">切换天气</button>
  </div>
</body>

<script type="text/javascript">
  var vm = new Vue({
    el: '#demo',
    data() {
      return {
        isHot: true,
        url: 'http://49.232.112.44/images/hot.jpg'
      }
    },
    computed: {
      text() {
        return this.isHot ? '凉' : '热'
      }
    },
    methods: {
      chanClick() {
        this.isHot = !this.isHot
      }
    },
    watch: {
      isHot: {
        handler(newValue, oldValue) {
          // console.log(newValue, oldValue)
          if (newValue) {
            this.url = 'http://49.232.112.44/images/hot.jpg'
          }
          else {
            this.url = 'http://49.232.112.44/images/cool.jpg'
          }
        }
      }
    }
  })

</script>

</html>